Ext.define('App.system.userForm', {
    extend      : 'Ext.window.Window',
    alias       : 'widget.userForm',
    initComponent : function() {
        var form = Ext.widget('form', {
            frame: false,
            border: true,
            split: true,
            autoScroll: true,
            bodyPadding: 5,
            bodyBorder: true,
            fieldDefaults: {
                labelWidth: 75,
                labelAlign: 'right',
                msgTarget: 'side'
            },
            defaults: {
                anchor: '100%'
            },
            items: [
                { xtype: 'hidden',
                    name: "id",
                    dataIndex: "id"
                },{ xtype: 'hidden',
                    name : "rolesId",
                    dataIndex : "rolesId"},
                { xtype: 'textfield',
                    name : "loginName",
                    dataIndex : "loginName",
                    fieldLabel : "登录名",
                    allowBlank : false
                },
                {    xtype: 'textfield',
                    name : "name",
                    dataIndex : "name",
                    fieldLabel : "用户姓名",
                    allowBlank : false
                },
                {     xtype: 'textfield',
                    name : "email",
                    dataIndex : "email",
                    fieldLabel : "邮箱",
                    allowBlank : true
                } ,Ext.create("comboBoxTree", {
                    name: 'rolesName',
                    hiddenValue: '',
                    storeUrl: getRootPath()+'/roleController/getList.action',
                    //cascade : 'both',//级联方式:1.child子级联;2.parent,父级联,3,both全部级联
                    checkModel: 'single',//当json数据为不带checked的数据时只配置为single,带checked配置为double为单选,不配置为多选
                    fieldLabel: '上级职位',
                    allowBlank: true,
                    labelWidth: 75,
                    rootVisible:false,
                    rootId: '',  //后天添加数据的时候root不计算在呢
                    treeNodeParameter: '',
                    callback: function (id, text) {
                        form.getForm().findField("rolesId").setValue(id);
                    }
                })
            ]
        });
        Ext.apply(this, {
            id : 'userWin',
            title : '用户新增',
            closable : true,
            layout : 'fit',
            height:300,
            width:500,
            modal : true,
            constrain : true,
            buttonAlign :'center',
            buttons : [ {
            text : "保存",
            handler : function() {
                var form = this.up('userForm').down('form');
                if (form.getForm().isValid()) {
                    form.getForm().submit({
                        url : 'userController/save.action',
                        scope : form,
                        success : function(form, action) {
                            this.up('userForm').close();
                            Ext.getCmp('userGrid').getStore().reload();
                        },
                        failure : function(form, action) {
                            if (action.result.message == undefined)
                                Ext.Msg.alert('错误', '网络连接失败.');
                            else
                                Ext.Msg.alert('错误', action.result.message);
                        },
                        waitMsg : '保存数据...'
                    });
                } else {
                    Ext.Msg.alert('提示', '表单含有无效或空数据');
                }
            },
            id : "btnSave"
        }, {
            text : "关闭",
            id : "btnClose",
            handler : function() {
                this.up('userForm').close();
            }
        } ],
            items : form
        });
        this.callParent();
    }
});